package br.com.empresa.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.GridLayout;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextPane;

import java.awt.Color;

import javax.swing.SwingConstants;

import java.awt.Font;

import javax.swing.JTable;
import javax.swing.JSeparator;
import javax.swing.UIManager;

import br.com.empresa.modelo.Cliente;
import br.com.persistencia.ClienteDao;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ClienteGUI extends JFrame {

	private JPanel contentPane;
	private JTextField txNomeCliente;
	private JTextField txCodigo;
	private JTextField txCPF;
	private JTextField txDataNascimento;
	private JTextField txTelefone;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ClienteGUI frame = new ClienteGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ClienteGUI() {
		setTitle("PetShop C\u00E3o & Gatos");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 539, 484);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new GridLayout(0, 1, 0, 0));
		
		JPanel panel = new JPanel();
		contentPane.add(panel);
		panel.setLayout(null);
		
		txNomeCliente = new JTextField();
		txNomeCliente.setBounds(119, 116, 228, 20);
		txNomeCliente.setColumns(10);
		panel.add(txNomeCliente);
		
		JLabel lblCodigo = new JLabel("C\u00F3digo");
		lblCodigo.setBounds(29, 88, 46, 14);
		panel.add(lblCodigo);
		
		txCodigo = new JTextField();
		txCodigo.setBounds(119, 85, 53, 20);
		txCodigo.setEditable(false);
		txCodigo.setColumns(10);
		panel.add(txCodigo);
		
		JLabel lblNomeCliente = new JLabel("Nome cliente :");
		lblNomeCliente.setBounds(29, 119, 88, 14);
		panel.add(lblNomeCliente);
		
		JLabel lblCPF = new JLabel("CPF:");
		lblCPF.setBounds(29, 144, 70, 14);
		panel.add(lblCPF);
		
		JLabel lblDataNascimento = new JLabel("Data Nascimento:");
		lblDataNascimento.setBounds(29, 172, 100, 14);
		panel.add(lblDataNascimento);
		
		txCPF = new JTextField();
		txCPF.setBounds(119, 141, 228, 20);
		txCPF.setColumns(10);
		panel.add(txCPF);
		
		txDataNascimento = new JTextField();
		txDataNascimento.setBounds(119, 169, 228, 20);
		txDataNascimento.setColumns(10);
		panel.add(txDataNascimento);
		
		JLabel lblTelefone = new JLabel("Telefone :");
		lblTelefone.setBounds(29, 200, 100, 14);
		panel.add(lblTelefone);
		
		txTelefone = new JTextField();
		txTelefone.setBounds(119, 197, 228, 20);
		txTelefone.setColumns(10);
		panel.add(txTelefone);
		
				
		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				Cliente c = new Cliente();
				c.setNome(txNomeCliente.getText());
				c.setCpf(txCPF.getText());
				c.setDataNascimento(AnimalGUI.formataData(txDataNascimento.getText()));
				c.setTelefone(txTelefone.getText());
				ClienteDao dao = new ClienteDao();
				
				if (txCodigo.getText().trim().equals("")) {
					dao.inserir(c);
				} else {
					c.setCodigo(Integer.parseInt(txCodigo.getText()));
					dao.editar(c);
				}
				
			}
		});
		btnSalvar.setBounds(316, 402, 89, 23);
		panel.add(btnSalvar);
		
		JButton btnLimpar = new JButton("Limpar");
		btnLimpar.setBounds(414, 402, 89, 23);
		panel.add(btnLimpar);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBounds(10, 11, 493, 51);
		panel.add(panel_2);
		panel_2.setLayout(null);
		panel_2.setBackground(new Color(173, 216, 230));
		
		JLabel lblCadastroDeCliente = new JLabel("Cadastro de Cliente");
		lblCadastroDeCliente.setFont(new Font("Times New Roman", Font.PLAIN, 14));
		lblCadastroDeCliente.setHorizontalAlignment(SwingConstants.CENTER);
		lblCadastroDeCliente.setForeground(Color.WHITE);
		lblCadastroDeCliente.setBounds(174, 11, 130, 35);
		panel_2.add(lblCadastroDeCliente);
	}
}
